In [1]:
import pandas as pd
coverage = pd.read_csv("../../notebooks/datasets/jacoco_production_coverage_spring_petclinic.csv")
coverage = coverage[
['PACKAGE',
'CLASS',
'LINE_COVERED',
'LINE_MISSED']]
coverage.head()
Out[1]:
In [2]:
coverage['lines'] = coverage['LINE_COVERED'] + coverage['LINE_MISSED']
coverage['ratio'] = coverage['LINE_COVERED'] / coverage['lines']
coverage['fqn'] = coverage['PACKAGE'] + "." + coverage['CLASS']
coverage[['fqn', 'ratio']].head()
Out[2]:
In [3]:
import py2neo
graph = py2neo.Graph()
query="""
UNWIND {coverage_data} as coverage
MATCH (t:Type {fqn : coverage.fqn})
MERGE (t)-[:HAS_MEASURE]->(m)
SET
m:Measure:Coverage,
m.ratio = coverage.ratio
RETURN t.fqn as fqn, m.ratio as ratio
"""
coverage_dict = coverage.to_dict(orient='records')
result = graph.run(query, coverage_data=coverage_dict).data()
pd.DataFrame(result).head()
Out[3]:
In [4]:
query = """
MATCH
(t:Type)-[:BELONGS_TO]->(s:Subdomain),
(t)-[:HAS_CHANGE]->(ch:Change),
(t)-[:HAS_MEASURE]->(co:Coverage)
OPTIONAL MATCH
(t)-[:HAS_BUG]->(b:BugInstance)
RETURN
s.name as ASubdomain,
COUNT(DISTINCT t) as Types,
COUNT(DISTINCT ch) as Changes,
AVG(co.ratio) as Coverage,
COUNT(DISTINCT b) as Bugs,
SUM(DISTINCT t.lastMethodLineNumber) as Lines
ORDER BY Coverage ASC, Bugs DESC
"""
In [5]:
result = pd.DataFrame(graph.run(query).data())
result
Out[5]:
In [6]:
plot_data = result.copy().set_index('ASubdomain')
plot_data = plot_data.rename(
columns= {
"Changes" : "Investment",
"Coverage" : "Utilization",
"Lines" : "Size"})
plot_data
Out[6]:
In [7]:
%matplotlib inline
from ausi.portfolio import plot_diagram
In [8]:
plot_diagram(plot_data, 'Investment', 'Utilization', 'Size');
In [9]:
query = """
MATCH
(t:Type)-[:IS_A]->(ta:TechnicalAspect),
(t)-[:HAS_CHANGE]->(ch:Change),
(t)-[:HAS_MEASURE]->(co:Coverage)
OPTIONAL MATCH
(t)-[:HAS_BUG]->(b:BugInstance)
RETURN
ta.name as ATechnicalAspect,
COUNT(DISTINCT t) as Types,
COUNT(DISTINCT ch) as Investment,
AVG(co.ratio) as Utilization,
COUNT(DISTINCT b) as Bugs,
SUM(DISTINCT t.lastMethodLineNumber) as Size
ORDER BY Utilization ASC, Bugs DESC
"""
In [10]:
result = pd.DataFrame(graph.run(query).data()).set_index('ATechnicalAspect')
result
Out[10]:
In [11]:
plot_diagram(result, 'Investment', 'Utilization', 'Size');